package cn.abcsys.cloud.devops.web.service.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.abcsys.cloud.devops.web.dao.EnvMapper;
import cn.abcsys.cloud.devops.web.entity.Env;
import cn.abcsys.cloud.devops.web.entity.GridBean;
import cn.abcsys.cloud.devops.web.entity.PagerModel;
import cn.abcsys.cloud.devops.web.service.EnvUserService;

@Service
public class EnvUserServiceImp implements EnvUserService {

	/*@Resource
	private EnvUserMapper envUserMapper;*/
	
	@Resource
	private EnvMapper envMapper;
	
	@Override
	public Env getEnvById(Integer envId) {
		// TODO Auto-generated method stub
		
		return envMapper.getEnvById(envId);
	}
	
	@Override
	public GridBean getEnvByName(Env env,PagerModel pagerModel) {
		int page = pagerModel.getPage();
		int rows = pagerModel.getRows();
		int totalpage = 0;
		Long totalNum = 0l;
		Page<Env> pageObject = new Page<Env>();
		Map<String,Object> map = new HashMap<>();
		map.put("envName", env.getEnvName());
		PageHelper.startPage(page, rows);
		List<Env> envList = envMapper.getEnv(map);
		for(Env en: envList){
			pageObject.add(en);
		}
		totalpage = ((Page<?>) envList).getPages();
		totalNum = ((Page<?>) envList).getTotal();
		GridBean gridBean = new GridBean(page, totalpage, totalNum.intValue(), pageObject);
		return gridBean;
	}

	@Override
	public int updateEnvById(Env env) throws SQLException {
		// TODO Auto-generated method stub
		
		return envMapper.updateEnvById(env);
		
	}

	@Override
	public int deleteEnvById(Integer envId) throws SQLException {
		// TODO Auto-generated method stub
		return envMapper.deleteEnvById(envId);
	}

	@Override
	public int createEnv(Env env) throws SQLException {
		// TODO Auto-generated method stub
		return envMapper.insertEnv(env);
	}

	@Override
	public List<Env> getAllEnv() {
		// TODO Auto-generated method stub
		return envMapper.getAllEnv();
	}
	
	
	
}
